<template>
  <div>
    <el-table
      :data="arr"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="商品编号"  >
        
      </el-table-column>
      <el-table-column prop="goodsname" label="商品名称"  >
      </el-table-column>
      <el-table-column prop="price" label="商品价格"  >
      </el-table-column>
      <el-table-column prop="market_price" label="市场价格"  >
      </el-table-column>
       <el-table-column prop="img" label="图片"  width="180">
        <template slot-scope="scope">
          <div>
            <img :src="$pre + scope.row.img" alt="" class="smallImg">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="是否新品">
        <template slot-scope="scope">
          <el-button type="primary" 
           v-if="scope.row.isnew == 1"   
            >启用</el-button
          >
          <el-button type="info"  v-else
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="是否热卖">
        <template slot-scope="scope">
          <el-button type="primary" 
           v-if="scope.row.ishot == 1"   
            >启用</el-button
          >
          <el-button type="info"  v-else
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" 
           v-if="scope.row.status == 1"   
            >启用</el-button
          >
          <el-button type="info"  v-else
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="edit(scope.row.id)"
            >编辑</el-button 
          >
          <el-button type="danger" 
            @click="del(scope.row.id)"
           >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {reqgoodsdelete} from '../../../http/api'
import { successAlert } from "../../../utils";
export default { 
    props:['info','arr'],
  data() {
      return {
       
      }
    },
  computed: {
    ...mapGetters({}),
  },
  methods: {
    ...mapActions({}),
   edit(id){
    this.info.isshow = true;
    this.info.isAdd = false;
    this.$emit('willUpdate',id)
   },
   del(id){
    // console.log(id);
    reqgoodsdelete({id}).then(res => {
      successAlert(res.data.msg);
      this.info.isshow = false;
      this.$emit('init');
    })
   }
  },
};
</script>
<style scoped lang="less">
.smallImg{
  width: 100%;
  height: 100%;
}
</style>